﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using PlugNT.Cms.Model;
using PlugNT.Cms.BLL;
using PlugNT.Common;
using PlugNT.Cms.Page;

namespace PlugNT.Cms.Web.Admin.Pre_Field
{
    public partial class Admin : AdminPage
    {
        private Field curField = new Field();
        private string currpostfix = "";
        private bool isall = true;
        protected void Page_Load(object sender, EventArgs e)
        {
            //权限检测
            this.CheckPower();

            currpostfix = (Request.QueryString["p"] == null) ? PlugNT.Custom.WebConfig.TablePostfix : Request.QueryString["p"].Trim();
            isall = (Request.QueryString["p"] == null);
            if (!IsPostBack)
            {
                    Repeater_admin_bind();
                try
                {

                }
                catch (Exception ex) { Response.Redirect("/Admin/Message.aspx?message=数据绑定错误！" + ex.Message + "&z=no"); }
            }
        }

        private void Repeater_admin_bind()
        {
            DataTable dt = isall ? curField.GetBindList() : curField.GetBindList(currpostfix);
            Repeater_admin.DataSource = dt.DefaultView;
            Repeater_admin.DataBind();
        }

        //判断是否存在文件
        protected void Repeater_admin_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Literal litHtmltype = (Literal)e.Item.FindControl("litHtmltype");
            Literal litColtype = (Literal)e.Item.FindControl("litColtype");
            DataRowView drv = (DataRowView)e.Item.DataItem;
            switch(drv["htmltype"].ToString())
            {
                case PlugNT.Custom.FieldHtmlType.textType:
                    litHtmltype.Text = "文本框";
                    break;
                case PlugNT.Custom.FieldHtmlType.textareaType:
                    litHtmltype.Text = "多行文本";
                    break;
                case PlugNT.Custom.FieldHtmlType.dropdownlistType:
                    litHtmltype.Text = "下拉列表";
                    break;
                case PlugNT.Custom.FieldHtmlType.editerType:
                    litHtmltype.Text = "编辑器";
                    break;
                default:
                    litHtmltype.Text = "未知类型";
                    break;
            }
            switch (drv["coltype"].ToString())
            {
                case PlugNT.Custom.FieldType.stringType:
                    litColtype.Text = "字符串";
                    break;
                case PlugNT.Custom.FieldType.integerType:
                    litColtype.Text = "整数";
                    break;
                case PlugNT.Custom.FieldType.datetimeType:
                    litColtype.Text = "日期";
                    break;
                default:
                    litColtype.Text = "未知类型";
                    break;
            }

        }

    }
}
